package com.definesys.smecrailtransit.module.EleRecord;

import android.content.Context;
import android.graphics.Color;
import android.view.View;

import com.bigkoo.pickerview.OptionsPickerView;
import com.definesys.smecrailtransit.R;
import com.definesys.smecrailtransit.api.SmecRailConstant;
import com.definesys.smecrailtransit.module.SiteDetails.bean.EleStation;
import com.definesys.smecrailtransit.utils.CommonUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.WeakHashMap;

import rx.Observable;

/**
 * Created by xupeizuo on 2018/4/24.
 */

public class EleRecordViewModel {

    private Context context;
    private OptionsPickerView siteOptions;
    private ArrayList<String> lineBeen = new ArrayList<>();
    private ArrayList<ArrayList<String>> arrayLists = new ArrayList<>();
    private HashMap<String,ArrayList<EleStation>> map;
    private WeakHashMap<String,Object> hashMap=new WeakHashMap<>();
    private EleRecordContract eleRecordContract;
    private int stationsPosition=0;

    public EleRecordViewModel(Context context,EleRecordContract contract) {
        this.context = context;
        this.eleRecordContract=contract;
        _initTitle();
    }

    public void siteClick(View view){
        switch (view.getId()){
            case R.id.change_site:
                if(siteOptions == null){
                    _showSites();
                }
                siteOptions.setSelectOptions(0, stationsPosition);//默认选中项
                siteOptions.show();
                break;
        }
    }

    private void _showSites(){

        siteOptions = new OptionsPickerView.Builder(context, new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                String line=lineBeen.get(options1);
                String stations=arrayLists.get(options1).get(options2);
                if(stations != null && !stations.equals("")){
                    ArrayList<EleStation> list=map.get(line);
                    if(CommonUtils.notEmpty(list)){
                        for(int i =0;i<list.size();i++){
                            EleStation eleStation=list.get(i);
                            if(eleStation.getStationName().equals(stations)){
                                hashMap.put("stationId",eleStation.getStationId());
                                hashMap.put("stationName",eleStation.getStationName());
                                eleRecordContract.siteSelected(hashMap);
                            }
                        }
                    }
                }
            }
        })
                .setTitleText("站点选择")
                .setContentTextSize(25)//设置滚轮文字大小
                .setDividerColor(Color.LTGRAY)//设置分割线的颜色
                .setBgColor(Color.WHITE)
                .setTitleBgColor(0xFF1980E5)
                .setTitleColor(Color.WHITE)
                .setCancelColor(Color.WHITE)
                .setSubmitColor(Color.WHITE)
                .setTextColorCenter(0xFF1980E5)
                .isCenterLabel(false) //是否只显示中间选中项的label文字，false则每项item全部都带有label。
                .setBackgroundId(0x66000000) //设置外部遮罩颜色
                .build();

        siteOptions.setPicker(lineBeen, arrayLists);//二级选择器
    }

    public void _initTitle(){
        lineBeen.add("12号线");
        map= SmecRailConstant.getMap();
        arrayLists=SmecRailConstant.getArrayLists();
    }

}
